#include "boundary.h"

#include "../hed/entity/edge.h"
#include "../hed/entity/vertex.h"



Boundary::Boundary( Edge* _edge, bool _inverted )
: m_edge( _edge )
, m_attribute( NULL )
, m_inverted( _inverted )
, m_subdiv( 1 )
{
}

vector<IPoint> 
Boundary::getSubdivisionPoints()
{
  vector<IPoint> pts;
  IPoint* p1 = NULL;
  IPoint* p2 = NULL;
  if( m_inverted )
  {
    p1 = m_edge->getSeconVertex()->getPoint();
    p2 = m_edge->getFirstVertex()->getPoint();
  } 
  else
  {
    p1 = m_edge->getFirstVertex()->getPoint();
    p2 = m_edge->getSeconVertex()->getPoint();
  }
  double dX = (p2->getX() - p1->getX()) / m_subdiv;
  double dY = (p2->getY() - p1->getY()) / m_subdiv;
  pts.push_back( *p1 );
  for( int i=1; i<m_subdiv; i++ )
  {
    double xi = p1->getX() + i*dX;
    double yi = p1->getY() + i*dY;
    IPoint pi( xi, yi, 0.0 );
    pts.push_back( pi );
  }
  pts.push_back( *p2 );
  return pts;
}


bool 
Boundary::isSelected()
{
  return m_edge->isSelected();
}


int 
Boundary::getSubdivisionNumber()
{
  return m_subdiv;
}


void 
Boundary::setSubdivisionNumber( int _subdiv )
{
  m_subdiv = _subdiv;
}
